//
//  BaseNavigationController.m
//  HelloSchool
//
//  Created by 赵卫东 on 15/10/19.
//  Copyright © 2015年 LangWang. All rights reserved.
//


#import "BaseNavigationController.h"
#import "UIColor+Categories.h"
//#import "UIBarButtonItem+MMSJ.h"
#import "UIImage+MMSJ.h"


@interface BaseNavigationController ()

@end

@implementation BaseNavigationController

/**
 *  第一次使用这个类的时候会调用(1个类只会调用1次)
 */
+ (void)initialize
{
    
    
    // 1.设置导航栏主题
    [self setupNavBarTheme];
    
    // 2.设置导航栏按钮主题
    [self setupBarButtonItemTheme];
    
}

/**
 *  设置导航栏按钮主题
 */
+ (void)setupBarButtonItemTheme
{
    UIBarButtonItem *item = [UIBarButtonItem appearance];
    
    // 设置文字属性
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    item.tintColor = BLACKTEXTCOLOR;
    textAttrs[NSForegroundColorAttributeName] = BLACKTEXTCOLOR;
    
    textAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:14];
    [item setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
    [item setTitleTextAttributes:textAttrs forState:UIControlStateHighlighted];
}

/**
 *  设置导航栏主题
 */
+ (void)setupNavBarTheme
{
    // 取出appearance对象
    UINavigationBar *navBar = [UINavigationBar appearance];
    
    // 设置标题属性
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    
    textAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:17 weight:UIFontWeightBold];
    
    textAttrs[NSForegroundColorAttributeName] = BLACKTEXTCOLOR;
    [navBar setTitleTextAttributes:textAttrs];
    [navBar setTintColor:THEMECOLOR];
    [navBar setBarTintColor:[UIColor whiteColor]];

//    [navBar setShadowImage:[UIImage new]];
    [navBar setTranslucent:NO];
}


- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{

    //修改返回键的图片 (普通和高亮)
    if (self.viewControllers.count >0) {
        viewController.hidesBottomBarWhenPushed = YES;
//        viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithPic:@"return" Highlighted:@"return" Target:self Action:@selector(back) Size:((CGSize){70,30})];
    }
    
//    UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"他人中心"  style:UIBarButtonItemStylePlain  target:self  action:nil];
//    [backButton setBackButtonBackgroundVerticalPositionAdjustment:1 forBarMetrics:UIBarMetricsDefault];
//    UIImage *img = [UIImage imageNamed:@"return"];
//    [self.navigationItem.backBarButtonItem setBackButtonBackgroundImage:[img stretchableImageWithLeftCapWidth:img.size.width-1 topCapHeight:img.size.height*0.5] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
    //    self.navigationItem.backBarButtonItem = backButton;
    
    [super pushViewController:viewController animated:animated];
}

- (void)back{
    [self popViewControllerAnimated:YES];
}

- (UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleDefault;

}

-(void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

@end
